﻿<Page
    x:Class="Toaster.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Toaster"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:Toaster.Data"
    mc:Ignorable="d">
    <Page.Resources>
        <data:ViewModel x:Key="ViewModel"/>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
            <Grid DataContext="{StaticResource ViewModel}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Margin="5" Text="Select a Toast Template:" Style="{StaticResource SubheaderTextBlockStyle}"/>
                <ListView Margin="0 10 0 0 " Grid.Row="1" ItemsSource="{Binding Toasts}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid Width="300" Height="200" Margin="5" Background="{StaticResource AppBarBorderThemeBrush}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock Text="{Binding Id}" Style="{StaticResource SubheaderTextBlockStyle}" Margin="5"/>
                                <TextBlock Text="{Binding Description}" TextWrapping="Wrap" Style="{StaticResource CaptionTextBlockStyle}" Grid.Row="1" Margin="5"/>
                                <TextBlock Text="{Binding Xml}" TextWrapping="Wrap" Grid.Row="3" Margin="5"></TextBlock>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                </ListView>
                <StackPanel Orientation="Horizontal" Grid.Row="3">
                    <TextBlock Text="Text Line 1:" Style="{StaticResource BaseTextBlockStyle}" Margin="5" Visibility="{Binding ShowLine1, Converter={StaticResource ShowThisConverter}}"/>
                    <TextBox Text="{Binding TextLine1, Mode=TwoWay}" Margin="5" Width="300" HorizontalAlignment="Left" Visibility="{Binding ShowLine1, Converter={StaticResource ShowThisConverter}}"/>
                    <TextBlock Text="Text Line 2:" Style="{StaticResource BaseTextBlockStyle}" Margin="5" Visibility="{Binding ShowLine2, Converter={StaticResource ShowThisConverter}}"/>
                    <TextBox Text="{Binding TextLine2, Mode=TwoWay}" Margin="5" Width="300" HorizontalAlignment="Left" Visibility="{Binding ShowLine2, Converter={StaticResource ShowThisConverter}}"/>
                    <TextBlock Text="Text Line 3:" Style="{StaticResource BaseTextBlockStyle}" Margin="5" Visibility="{Binding ShowLine3, Converter={StaticResource ShowThisConverter}}"/>
                    <TextBox Text="{Binding TextLine3, Mode=TwoWay}" Margin="5" Width="300" HorizontalAlignment="Left" Visibility="{Binding ShowLine3, Converter={StaticResource ShowThisConverter}}"/>
                </StackPanel>
                <StackPanel Grid.Row="4" Orientation="Horizontal" Visibility="{Binding ShowImage, Converter={StaticResource ShowThisConverter}}">
                    <TextBlock Text="Select Your Image:" Style="{StaticResource BaseTextBlockStyle}" Margin="5"/>
                    <ListView Background="LightGray" ItemsSource="{Binding Images}" SelectedItem="{Binding SelectedImage, Mode=TwoWay}">
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal"/>
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Image Source="{Binding Converter={StaticResource BitmapImageConverter}}" Width="50" Height="50"/>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </StackPanel>
                <StackPanel Grid.Row="5" Orientation="Horizontal" Height="40">
                    <TextBlock Text="Enter Delay (Seconds):" Margin="5" Style="{StaticResource BaseTextBlockStyle}" VerticalAlignment="Center"/>
                    <Slider Minimum="1" Maximum="300" Width="300" Value="{Binding DelaySeconds, Mode=TwoWay}" Margin="10 0 0 0" VerticalAlignment="Center"/>
                    <TextBlock Text="{Binding DelaySeconds}" Style="{StaticResource BaseTextBlockStyle}" Margin="5 0 0 0" VerticalAlignment="Center"/>
                </StackPanel>
                <StackPanel Grid.Row="6" Orientation="Horizontal" Height="40">
                    <TextBlock Text="Silent?" Style="{StaticResource BaseTextBlockStyle}" Margin="10 0 0 0" VerticalAlignment="Center"/>
                    <CheckBox IsChecked="{Binding Silent, Mode=TwoWay}"/>
                    <TextBlock Visibility="{Binding Silent, Converter={StaticResource ShowThisConverter}, ConverterParameter='reverse'}" Text="Audio Type: " Margin="10 0 0 0" Style="{StaticResource BaseTextBlockStyle}" VerticalAlignment="Center"/>
                    <ComboBox Visibility="{Binding Silent, Converter={StaticResource ShowThisConverter}, ConverterParameter='reverse'}" ItemsSource="{Binding AudioTypes}" DisplayMemberPath="DisplayType" SelectedItem="{Binding SelectedAudio, Mode=TwoWay}" VerticalAlignment="Center" Margin="5 0 0 0"/>
                    <TextBlock Visibility="{Binding IsLoopCapable, Converter={StaticResource ShowThisConverter}}" Text="Loop?" Margin="10 0 0 0" Style="{StaticResource BaseTextBlockStyle}" VerticalAlignment="Center"/>
                    <CheckBox Visibility="{Binding IsLoopCapable, Converter={StaticResource ShowThisConverter}}" IsChecked="{Binding Loop, Mode=TwoWay}" VerticalAlignment="Center"></CheckBox>
                </StackPanel>
                <Button Grid.Row="7" Content="Send" Margin="5" Command="{Binding}"/>
            </Grid>
        </ScrollViewer>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock x:Name="pageTitle" Text="Toaster" Style="{StaticResource HeaderTextBlockStyle}" 
                       VerticalAlignment="Bottom"
                       Margin="30,0,30,40"
                       Grid.Column="1" IsHitTestVisible="false"/>
        </Grid>
    </Grid>
</Page>
